package ar.com.jwa.controllers;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import ar.com.jwa.domain.User;
import ar.com.jwa.services.SystemFacade;

@Controller
public class GameController {

	@Autowired
	private SystemFacade systemFacade;

	
	/**
	 * Mètodo del Controller que buscar la lista de jugadores confirmados para un partido cuyo id es pasado por paràmetro.
	 * @param req
	 * @param res
	 * @param session
	 * @return
	 */
	@RequestMapping("/getConfirmedPlayers.*")
	@Transactional(propagation = Propagation.REQUIRED,readOnly = true)
	public ModelAndView getConfirmedPlayers(HttpServletRequest req, HttpServletResponse res,HttpSession session){
		
		Map<String, Object> model = new HashMap<String, Object>();
		
		String gameId = req.getParameter("gameId");
		
		Collection<User> confirmedPlayers = this.getSystemFacade().getConfirmedPlayersForGame(gameId);
		
		model.put("confirmedPlayers",confirmedPlayers);
		
		return new ModelAndView("playersTable",model);
	}


	/**
	 * @return the systemFacade
	 */
	public SystemFacade getSystemFacade() {
		return systemFacade;
	}


	/**
	 * @param systemFacade the systemFacade to set
	 */
	public void setSystemFacade(SystemFacade systemFacade) {
		this.systemFacade = systemFacade;
	}

}
